var spanbtnobj = document.querySelector('.member div>span:nth-of-type(1)')
spanbtnobj.onclick=function(){
   var itemTK = document.querySelector('.login .item')
   itemTK.style.visibility='visible'
}
var gbbtnobj = document.querySelector('.close')
gbbtnobj.onclick = function(){
    var item = document.querySelector('.login .item')
   item.style.visibility='hidden'
   
}
var menuobj = document.querySelector('.menu')

menuobj.onmousedown = function(evt){
    var oldE = evt || window.event
    document.onmousemove = function(evt){
      var e = evt || window.event
      var left = e.clientX-oldE.offsetX
      var top = e.clientY-oldE.offsetY
      var itemobj = document.querySelector('.login .item')
      var maxw= document.innerWidth || document.documentElement.clientWidth-itemobj.offsetWidth
    
       var maxh = document.innerHeight || document.documentElement.clientHeight-itemobj.offsetHeight
       if (left<0) left = 0
       if (top<0) top = 0
      if(maxh<top)top=maxh
      if(maxw<left)left=maxw
   
   itemobj.style.position='absolute'
   itemobj.style.left=left+'px'
   itemobj.style.top=top+'px'
    }    
    
}

document.onmouseup=function(){
    document.onmousemove = null
}




var num = 5
var captcha = document.querySelector('section.login .captcha') 
captcha.onclick=function(){
// 行为验证码
var xwyzmobj = document.querySelector('section.captcha')
xwyzmobj.style.visibility = 'visible'
var xwyzmbtnobj = document.querySelector('section.captcha i')
xwyzmbtnobj.onclick=function(){
    xwyzmobj.style.visibility = 'hidden'
}
// 球球拖拽
var qiuqiubtnobj = document.querySelector('section.captcha .drag .btn')
var imgobj = document.querySelector('section.captcha .check img:nth-of-type(2)')

qiuqiubtnobj.onmousedown=function(){
    document.onmousemove=function(evt){
        var e = evt || window.event
       
        var left = e.clientX-(xwyzmobj.offsetLeft-xwyzmobj.offsetWidth/2)-qiuqiubtnobj.offsetWidth/2
        var maxleft = xwyzmobj.offsetWidth-imgobj.offsetWidth
        console.log(maxleft)
    if(left>maxleft)left=maxleft
    if(left<=0)left=0

        qiuqiubtnobj.style.left = left+'px'
    document.querySelector('section.captcha .check img:nth-of-type(2) ').style.left=left+'px'
    
   
    }
    document.onmouseup=function(){
        document.onmousemove=null
        var value = parseInt(qiuqiubtnobj.style.left)
      
        if(value>=260 && value<=265){
            xwyzmobj.style.visibility = 'hidden'
            captcha.innerText=num+'秒后重新获取'
            captcha.disabled = true
    t = setInterval(function(){
       
        if(num<=1){
            clearInterval(t)
            captcha.innerText='重新发送'
            num=5
            captcha.disabled = false

            return

        }
        num--
        captcha.innerText=num+'秒后重新获取'

    },1000)
   

        }
        qiuqiubtnobj.style.left = 0+'px'
        document.querySelector('section.captcha .check img:nth-of-type(2) ').style.left=0+'px'
    }
}





}
var isok = 0
var submitobj = document.querySelector('section.login .submit')
submitobj.onclick=function(){
    var mobileobj = document.querySelector('section.login .mobile')
    if(mobileobj.value=='' || mobileobj.value.length!=11 || !Number(mobileobj.value)){
        document.querySelector('section.login .msg').innerText='手机号格式有误'     
    }else{
        isok++
        document.querySelector('section.login .msg').innerText=''     
    }
    var passwordobj = document.querySelector('section.login .password')
    if(passwordobj.value=='' || passwordobj.value.length!=4 || !Number(passwordobj.value)){
        document.querySelector('section.login .form>p:nth-of-type(4)').innerText='验证码输入错误'
    }else{
        isok++
        document.querySelector('section.login .form>p:nth-of-type(4)').innerText=''
    }
    if(isok==2){
        alert('登录成功')
    }
}
 
   setInterval(function(){
    var hotobj = document.querySelector('section.hot ul')
    var marginLeft = parseInt(hotobj.style.marginLeft)
    marginLeft--
    if(marginLeft<=-2032){
        hotobj.style.marginLeft = 0+'px'
    }else{
        hotobj.style.marginLeft = marginLeft+'px'
    }
   },10)
// 分页器
function fyq(i){
    var fyqobj = document.querySelectorAll('.lbt .swiper-pagination span')
    fyqobj.forEach(function(item,index){
        item.className=''
    })
    fyqobj[i].className = 'swiper-pagination-active'
}

// 轮播图
var num1 = 1 
var t
 function lbtobj(){
   t = setInterval(function(){
        num1++
        if(num1==7){
            num1=1
        }
        var tp = document.querySelector('.lbt .swiper .swiper-wrapper img')
        tp.src='./assets/imgs/b'+num1+'.jpeg'

       fyq(num1-1)
    },2000)
 }
 lbtobj()

// 移入移除分页器
    var qfyqobj = document.querySelectorAll('.lbt .swiper-pagination span')
    qfyqobj.forEach(function(item,index){
        item.onmouseover=function(){
            clearInterval(t)
            document.querySelector('.lbt .swiper .swiper-wrapper img').src='./assets/imgs/b'+(index+1)+'.jpeg'
            fyq(index)
            num1 = index+1
        }
        item.onmouseout=function(){
            lbtobj()
        }
    })
//    左右按钮
    var swiperbuttonprevobj = document.querySelector('.lbt .swiper .swiper-button-prev')
    var swiperbuttonnextobj = document.querySelector('.lbt .swiper .swiper-button-next')
    swiperbuttonprevobj.onmouseover=function(){
        clearInterval(t)
        swiperbuttonprevobj.onmousedown=function(){
            num1--
            if(num1<1)num1=6
            document.querySelector('.lbt .swiper .swiper-wrapper img').src='./assets/imgs/b'+num1+'.jpeg'
            if(num1<1)num1=6
            fyq(num1-1)
        }
        swiperbuttonprevobj.onmouseout=function(){
            lbtobj()
        }
    }

    swiperbuttonnextobj.onmouseover=function(){
        clearInterval(t)
        swiperbuttonnextobj.onmousedown=function(){
            num1++
            if(num1>6)num1=1
            document.querySelector('.lbt .swiper .swiper-wrapper img').src='./assets/imgs/b'+num1+'.jpeg'
            fyq(num1-1)
        }
        swiperbuttonnextobj.onmouseout=function(){
            lbtobj()
        }
    }
    // 网页头部进度条
//     var num=0
// var over = false
// var t = setInterval(function() {
//     var nprogress = document.querySelector('.nprogress')
//     if(num>=95 && !over) return
//     num++
//     if (nprogress) {
//         nprogress.style.width = num+'%'
//     } else {
//         var nprogress = document.createElement('div')
//         nprogress.className = 'nprogress'
//         nprogress.style.position = 'fixed'
//         nprogress.style.top = 0
//         nprogress.style.width = num+'%'
//         nprogress.style.height = '5px'
//         nprogress.style.backgroundColor = '#29d'
//         document.body.appendChild(nprogress) 
//         var nprogressRadius = document.createElement('div')
//         nprogressRadius.className = 'nprogressRadius'
//         document.body.appendChild(nprogressRadius)
//     }
//     if (num>=110) {
//         document.body.removeChild(nprogress)
//         clearInterval(t)

//         document.body.removeChild(document.querySelector('.nprogressRadius'))
//     }
// }, 10)
// window.onload = function() {
//     over = true
// }
